/**
' Project must reference COM type library "Primavera Portfiolio Management Open API Interface"
'
' This is a part of the Primavera Portfiolio Management API examples.
' Copyright 1998, 2020, Oracle and/or its affiliates. All Rights Reserved.
'
' This source code is only intended as a supplement to the
'   Primavera Portfolio Management Enterprise API
' electronic documentation provided with the product.
'
' This source code is compatible with Primavera Portfolio Management 20.0 
**/

//*************************************************
// Get list of values in 'Domains' value list
//*************************************************

using System;
using System.Windows.Forms;

// needed for COMException object 
using System.Runtime.InteropServices;

using psPortfoliosLib;

namespace CSharpExamples 
{
        public class CpsPortfoliosValueList_GetValues_Example_1
        {
                string mToken;
        
                public void Login() 
                {
                        try
                        {
                                psPortfoliosSecurity psSecurity = new psPortfoliosSecurity();
                                mToken = psSecurity.Login("admin", "Password", 10000); // Never code the password in the source file    
                        }
                        catch (COMException E) 
                        {
                                // in case of exception, print the error info
                                MessageBox.Show("Error " + 
                                                (psRETURN_VALUES)(-E.ErrorCode) +  // negate the number to obtain the real error code
                                                " " + E.Message, 
                                                "Login");
                                                // in a real system, the description is only displayed to support personnel, 
                                                // not to the user
                        }                       
                        catch (Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                                E.ToString(), 
                                                "Login");
                        }                                       
                        
                }
                
                public void psPortfoliosValueList_GetValues_Example_1() 
                {

                        try 
                        {

                                psPortfoliosValueList ValueListObj = new psPortfoliosValueList();    

                                ValueListObj.SetSecurity(mToken);


                                object retVal = ValueListObj.GetValues(
                                        @"Domains"  // sName             
                                        );
                         
                                psVariantArrayFromOutput vaArray = new psVariantArrayFromOutputClass();
                                vaArray.CreateFromVariantArray(ref retVal); 

                                string msg = "Total of " + vaArray.Length() + " results:\n";
                        
                        #region Analyze result                  
                        
                                int i=0;
                                while(vaArray.HasMoreItems()) 
                                {
                                        psPortfoliosValueListValueInfo infoObj = (psPortfoliosValueListValueInfo) vaArray.NextItem();
                                        int ID = infoObj.ID;
                                        string Text = infoObj.Text;
                                        float Weight = infoObj.Weight;
										double WeightDouble = infoObj.WeightDouble;

                                        msg += (i++) + ": ";
                                        msg += "ID=" + ID + ", ";
                                        msg += "Text=" + Text + ", ";
										msg += "Weight=" + Weight + ", ";
                                        msg += "WeightDouble=" + WeightDouble + "\n";
                                }            
                                
                        #endregion Analyze result                               
                                
                                MessageBox.Show(msg, @"Get list of values in 'Domains' value list");
          
                                ValueListObj.ReleaseValues(ref retVal);
                        } 
                        catch (COMException E) 
                        {
                                // in case of exception, print the error info
                                MessageBox.Show("Error " + 
                                                (psRETURN_VALUES)(-E.ErrorCode) +  // negate the number to obtain the real error code
                                                " " + E.Message, 
                                                @"Get list of values in 'Domains' value list");
                                                // in a real system, the description is only displayed to support personnel, 
                                                // not to the user
                        }
                        catch (Exception E) 
                        {
                                MessageBox.Show("Unexcpected Error: \n" + 
                                                E.ToString(),
                                                @"Get list of values in 'Domains' value list");
                        }                  
                }
        }
}
    

